﻿<UserControl x:Class="MavlinkPacketViewer.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="120" d:DesignWidth="717" 
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
    xmlns:MavlinkDebugger="clr-namespace:MavlinkDebugger" 
    xmlns:DataGrid="clr-namespace:Jib.Controls.DataGrid;assembly=Jib.Controls" xmlns:Converters="clr-namespace:MavlinkPacketViewer.Converters">
    <UserControl.Resources>
        <Converters:BooleanToVisibilityConverter x:Key="boolToVis"/>
        <Converters:BooleanNotConverter x:Key="boolNot"/>

        
    </UserControl.Resources>
    

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal">
        
        <Button Height="30" Width="100" Click="ButtonClick"
                Name="btnLoad"
                Content="Load"
                Margin="5,0,5,0"
                IsEnabled="{Binding IsLoading, Converter={StaticResource boolNot}}"
                Grid.Row="0"></Button>

            <StackPanel Orientation="Vertical" Margin="0,10,20,0" 
                        
                        >
                <RadioButton Name="rdoMavlinkFormat" IsChecked="True" GroupName="MavlinkLogFormat" 
                             Content="Mavlink Log format"
                             ToolTipService.ToolTip="Log format of APM Planner and QGroundControl"
                              IsEnabled="{Binding IsLoading, Converter={StaticResource boolNot}}"
                             />
                <RadioButton Name="rdoRawFormat" GroupName="MavlinkLogFormat" 
                             Content="Raw format" 
                             ToolTipService.ToolTip="Raw Mavlink stream"
                              IsEnabled="{Binding IsLoading, Converter={StaticResource boolNot}}"
                             />
            </StackPanel>
            
        <Button Height="30" Width="100" Margin="0,0,5,0" Click="ViewSelectedBytes"
                Content="Show Bytes"
                Name="btnShowBytes"
                IsEnabled="False"
                
                Grid.RowSpan="1" Grid.Row="0"></Button>

            <Button Height="30" Width="100" Margin="0" Click="ViewPacket"
                Content="Show Packet"
                Name="btnShowPacket"
                    IsEnabled="False"
                Grid.RowSpan="1" Grid.Row="0"></Button>

            <TextBlock Name="txtProgress" Width="50" HorizontalAlignment="Right" VerticalAlignment="Center"
                   Margin="10,0,0,0"
                   Text="{Binding ProgressText}"
                   Visibility="{Binding IsLoading, Converter={StaticResource boolToVis}}"    
                       />
        </StackPanel>

        <DataGrid:JibGrid
            Grid.Row="1" 
            Name="mavlinkItemsDataGrid"
            AutoGenerateColumns="False"
            SelectionChanged="MavlinkItemsDataGridSelectionChanged"
            FilteredItemsSource="{Binding Items}"
            IsReadOnly="True"
            LoadingRow="MavlinkItemsDataGridLoadingRow"
            UnloadingRow="MavlinkItemsDataGridUnloadingRow">
        	<DataGrid:JibGrid.Resources>
                <DataTemplate x:Key="cellTemplatePosition">
                    <TextBlock Text="{Binding  ItemPosition}" VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
                </DataTemplate>
                <Style x:Key="TextColAlignRight" TargetType="data:DataGridCell">
                    <Setter Property="HorizontalContentAlignment" Value="Right" />
                </Style>
                
            </DataGrid:JibGrid.Resources>

            <data:DataGrid.Columns>
                <data:DataGridTextColumn Header="Time Stamp (UTC)" Binding="{Binding TimeStamp, StringFormat=\{0:dd/MM/yy HH:mm:ss.fff\}}" Width="140" />
                <data:DataGridTextColumn Header="Time Offset" Binding="{Binding TimeStampOffset, StringFormat=\{0:G\}}" Width="110" />
                <data:DataGridTextColumn Header="Type" Binding="{Binding ItemTypeString}" Width="80" />
                <data:DataGridTextColumn Header="Stream Position"  Binding="{Binding BytePosition}" CellStyle="{StaticResource TextColAlignRight}" Width="100"  />
                <data:DataGridTextColumn Header="Position" Binding="{Binding ItemPosition}" CellStyle="{StaticResource TextColAlignRight}"  Width="70"/>
                <data:DataGridTextColumn Header="Size" Binding="{Binding Size}" CellStyle="{StaticResource TextColAlignRight}" Width="70"/>
                <data:DataGridTextColumn Header="Seq" Binding="{Binding SequenceNumber}" CellStyle="{StaticResource TextColAlignRight}" Width="70"/>
                <data:DataGridTextColumn Header="Sys Id" Binding="{Binding SystemId}" CellStyle="{StaticResource TextColAlignRight}" Width="70"/>
                <data:DataGridTextColumn Header="Comp Id" Binding="{Binding ComponentId}" CellStyle="{StaticResource TextColAlignRight}" Width="70" />
                <data:DataGridTextColumn Header="Mavlink Message" Binding="{Binding Message}" Width="160" />

            </data:DataGrid.Columns>
            </DataGrid:JibGrid>

    </Grid>
</UserControl>
